import { defineStore } from "pinia";
import { ref, computed, onMounted } from "vue";

export const useUserStore = defineStore("user", () => {
  // 用户基本信息
  const userInfo = ref({
    id: "",
    username: "",
    nickname: "",
    avatar: "",
    phone: "",
    email: "",
    gender: 0, // 0:未知 1:男 2:女
    birthday: "",
    address: "",
    createTime: "",
  });

  // 清除用户信息
  const clearUserInfo = () => {
    userInfo.value = {
      id: "",
      username: "",
      nickname: "",
      avatar: "",
      phone: "",
      email: "",
      gender: 0,
      birthday: "",
      address: "",
      createTime: "",
    };
  };

  // 计算属性：判断用户是否已登录
  const isLoggedIn = computed(() => !!userInfo.value.id);

  return {
    // 状态
    userInfo,
    isLoggedIn,
  };
});
